{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "from template.engineering_rules import RuleManager\n",
    "from core.excel_writer import DirectTemplateWriter\n",
    "from config.path import path_manager\n",
    "from config.project_info import PROJECT_BASE_INFO\n",
    "import os\n",
    "from TimeManager import TimeManager\n",
    "from frame.ConstructionDataProcessor import ConstructionDataProcessor\n",
    "from model import RuleProcessor\n",
    "from YAMLUpdaterWithOutput import YAMLUpdaterWithOutput_baziqiang\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 要执行的规则模块列表\n",
    "RULE_MODULES = [\n",
    "    {\"rule_module\": \"GL105\", \"rule_class\": \"GL105_Rule\"},\n",
    "    {\"rule_module\": \"JS101\", \"rule_class\": \"JS101Rule\" },\n",
    "    {\"rule_module\": \"JS103\", \"rule_class\": \"JS103_Rule\"},\n",
    "    {\"rule_module\": \"JS107\", \"rule_class\": \"JS107_Rule\"},\n",
    "    {\"rule_module\": \"JS108\", \"rule_class\": \"JS108_Rule\"},\n",
    "    {\"rule_module\": \"JS111\", \"rule_class\": \"JS111_Rule\"},\n",
    "    {\"rule_module\": \"JS601_1\", \"rule_class\": \"JS601_1_Rule\"},\n",
    "    {\"rule_module\": \"JS703\", \"rule_class\": \"JS703_Rule\"},\n",
    "    {\"rule_module\": \"ZJ403\", \"rule_class\": \"ZJ403_Rule\"},\n",
    "    {\"rule_module\": \"ZJ904\", \"rule_class\": \"ZJ904_Rule\"},\n",
    "    {\"rule_module\": \"ZJ812\", \"rule_class\": \"ZJ812_Rule\"},\n",
    "]\n",
    "\n",
    "# 输出顺序控制\n",
    "SHEET_WRITE_ORDER = [\"GL105\", \"JS101\", \"JS103\",\"JS107\", \"JS108\",\"JS601_1\",\"JS111\", \"JS703\", \"ZJ403\",\"ZJ904\", \"ZJ812\"]   \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "# step 1: 创建数据处理对象\n",
    "processor = ConstructionDataProcessor()\n",
    "final_df = processor.process()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>轴线</th>\n",
       "      <th>类型</th>\n",
       "      <th>施工部位</th>\n",
       "      <th>匹配部位</th>\n",
       "      <th>左右幅</th>\n",
       "      <th>施工日期</th>\n",
       "      <th>强度等级</th>\n",
       "      <th>数量m³</th>\n",
       "      <th>原始桩号</th>\n",
       "      <th>最近桩号</th>\n",
       "      <th>坐标N(X)</th>\n",
       "      <th>坐标E(Y)</th>\n",
       "      <th>两者距离(米)</th>\n",
       "      <th>涵底中心标高</th>\n",
       "      <th>实际涵长</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>K44+217</td>\n",
       "      <td>圆管涵</td>\n",
       "      <td>圆管涵基础</td>\n",
       "      <td>基础</td>\n",
       "      <td></td>\n",
       "      <td>2024-05-01</td>\n",
       "      <td>C25</td>\n",
       "      <td>68.4</td>\n",
       "      <td>K44+217</td>\n",
       "      <td>K44+220</td>\n",
       "      <td>3241873.418</td>\n",
       "      <td>496220.823</td>\n",
       "      <td>3.00</td>\n",
       "      <td>29.56</td>\n",
       "      <td>46.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>K44+628</td>\n",
       "      <td>圆管涵</td>\n",
       "      <td>圆管涵基础</td>\n",
       "      <td>基础</td>\n",
       "      <td>左幅</td>\n",
       "      <td>2024-05-08</td>\n",
       "      <td>C25</td>\n",
       "      <td>45.0</td>\n",
       "      <td>K44+628</td>\n",
       "      <td>K44+628.020</td>\n",
       "      <td>3241595.046</td>\n",
       "      <td>495922.511</td>\n",
       "      <td>0.02</td>\n",
       "      <td>32.00</td>\n",
       "      <td>62.29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>K44+628</td>\n",
       "      <td>圆管涵</td>\n",
       "      <td>圆管涵基础</td>\n",
       "      <td>基础</td>\n",
       "      <td>右幅</td>\n",
       "      <td>2024-05-11</td>\n",
       "      <td>C25</td>\n",
       "      <td>47.0</td>\n",
       "      <td>K44+628</td>\n",
       "      <td>K44+628.020</td>\n",
       "      <td>3241595.046</td>\n",
       "      <td>495922.511</td>\n",
       "      <td>0.02</td>\n",
       "      <td>32.00</td>\n",
       "      <td>62.29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>K45+084</td>\n",
       "      <td>圆管涵</td>\n",
       "      <td>圆管涵基础</td>\n",
       "      <td>基础</td>\n",
       "      <td></td>\n",
       "      <td>2024-05-18</td>\n",
       "      <td>C25</td>\n",
       "      <td>60.0</td>\n",
       "      <td>K45+084</td>\n",
       "      <td>K45+080</td>\n",
       "      <td>3241286.683</td>\n",
       "      <td>495592.060</td>\n",
       "      <td>4.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>K48+224</td>\n",
       "      <td>圆管涵</td>\n",
       "      <td>圆管涵基础</td>\n",
       "      <td>基础</td>\n",
       "      <td></td>\n",
       "      <td>2024-05-24</td>\n",
       "      <td>C25</td>\n",
       "      <td>60.0</td>\n",
       "      <td>K48+224</td>\n",
       "      <td>K48+224</td>\n",
       "      <td>3240696.500</td>\n",
       "      <td>492608.235</td>\n",
       "      <td>0.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>347</th>\n",
       "      <td>K44+861</td>\n",
       "      <td>盖板涵</td>\n",
       "      <td>左幅盖板</td>\n",
       "      <td>盖板</td>\n",
       "      <td></td>\n",
       "      <td>2025-05-07</td>\n",
       "      <td>C40</td>\n",
       "      <td>24.0</td>\n",
       "      <td>K44+861</td>\n",
       "      <td>K44+860</td>\n",
       "      <td>3241436.778</td>\n",
       "      <td>495752.906</td>\n",
       "      <td>1.00</td>\n",
       "      <td>40.30</td>\n",
       "      <td>44.64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>348</th>\n",
       "      <td>K44+861</td>\n",
       "      <td>盖板涵</td>\n",
       "      <td>左幅盖板第二模</td>\n",
       "      <td>盖板</td>\n",
       "      <td></td>\n",
       "      <td>2025-05-09</td>\n",
       "      <td>C40</td>\n",
       "      <td>13.0</td>\n",
       "      <td>K44+861</td>\n",
       "      <td>K44+860</td>\n",
       "      <td>3241436.778</td>\n",
       "      <td>495752.906</td>\n",
       "      <td>1.00</td>\n",
       "      <td>40.30</td>\n",
       "      <td>44.64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>349</th>\n",
       "      <td>K44+861</td>\n",
       "      <td>盖板涵</td>\n",
       "      <td>左幅八字墙基础</td>\n",
       "      <td>八字墙</td>\n",
       "      <td></td>\n",
       "      <td>2025-05-11</td>\n",
       "      <td>C20</td>\n",
       "      <td>6.0</td>\n",
       "      <td>K44+861</td>\n",
       "      <td>K44+860</td>\n",
       "      <td>3241436.778</td>\n",
       "      <td>495752.906</td>\n",
       "      <td>1.00</td>\n",
       "      <td>40.30</td>\n",
       "      <td>44.64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>350</th>\n",
       "      <td>K42+867</td>\n",
       "      <td>圆管涵</td>\n",
       "      <td>一字墙</td>\n",
       "      <td>一字墙</td>\n",
       "      <td></td>\n",
       "      <td>2025-05-12</td>\n",
       "      <td>C20</td>\n",
       "      <td>9.0</td>\n",
       "      <td>K42+867</td>\n",
       "      <td>K42+866.590</td>\n",
       "      <td>3242794.987</td>\n",
       "      <td>497211.956</td>\n",
       "      <td>0.41</td>\n",
       "      <td>35.06</td>\n",
       "      <td>50.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>351</th>\n",
       "      <td>K41+500</td>\n",
       "      <td>盖板涵</td>\n",
       "      <td>基础</td>\n",
       "      <td>基础</td>\n",
       "      <td></td>\n",
       "      <td>2025-05-15</td>\n",
       "      <td>C35</td>\n",
       "      <td>60.0</td>\n",
       "      <td>K41+500</td>\n",
       "      <td>K41+500</td>\n",
       "      <td>3243160.345</td>\n",
       "      <td>498486.035</td>\n",
       "      <td>0.00</td>\n",
       "      <td>31.30</td>\n",
       "      <td>39.30</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>352 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          轴线   类型     施工部位 匹配部位 左右幅       施工日期 强度等级  数量m³     原始桩号  \\\n",
       "0    K44+217  圆管涵    圆管涵基础   基础     2024-05-01  C25  68.4  K44+217   \n",
       "1    K44+628  圆管涵    圆管涵基础   基础  左幅 2024-05-08  C25  45.0  K44+628   \n",
       "2    K44+628  圆管涵    圆管涵基础   基础  右幅 2024-05-11  C25  47.0  K44+628   \n",
       "3    K45+084  圆管涵    圆管涵基础   基础     2024-05-18  C25  60.0  K45+084   \n",
       "4    K48+224  圆管涵    圆管涵基础   基础     2024-05-24  C25  60.0  K48+224   \n",
       "..       ...  ...      ...  ...  ..        ...  ...   ...      ...   \n",
       "347  K44+861  盖板涵     左幅盖板   盖板     2025-05-07  C40  24.0  K44+861   \n",
       "348  K44+861  盖板涵  左幅盖板第二模   盖板     2025-05-09  C40  13.0  K44+861   \n",
       "349  K44+861  盖板涵  左幅八字墙基础  八字墙     2025-05-11  C20   6.0  K44+861   \n",
       "350  K42+867  圆管涵      一字墙  一字墙     2025-05-12  C20   9.0  K42+867   \n",
       "351  K41+500  盖板涵       基础   基础     2025-05-15  C35  60.0  K41+500   \n",
       "\n",
       "            最近桩号       坐标N(X)      坐标E(Y)  两者距离(米)  涵底中心标高   实际涵长  \n",
       "0        K44+220  3241873.418  496220.823     3.00   29.56  46.50  \n",
       "1    K44+628.020  3241595.046  495922.511     0.02   32.00  62.29  \n",
       "2    K44+628.020  3241595.046  495922.511     0.02   32.00  62.29  \n",
       "3        K45+080  3241286.683  495592.060     4.00     NaN    NaN  \n",
       "4        K48+224  3240696.500  492608.235     0.00     NaN    NaN  \n",
       "..           ...          ...         ...      ...     ...    ...  \n",
       "347      K44+860  3241436.778  495752.906     1.00   40.30  44.64  \n",
       "348      K44+860  3241436.778  495752.906     1.00   40.30  44.64  \n",
       "349      K44+860  3241436.778  495752.906     1.00   40.30  44.64  \n",
       "350  K42+866.590  3242794.987  497211.956     0.41   35.06  50.50  \n",
       "351      K41+500  3243160.345  498486.035     0.00   31.30  39.30  \n",
       "\n",
       "[352 rows x 15 columns]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "final_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "filtered_df = final_df.dropna(how='any')\n",
    "filtered_data = filtered_df[filtered_df['类型'] == '圆管涵']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "updater = YAMLUpdaterWithOutput_baziqiang(\n",
    "        filepath=r\"/Users/chenhongbin/myapp1/highway-information/圆管涵/项目基本信息_圆管涵(八字墙).yaml\",\n",
    "        output_dir=\"output/分组yaml1\"\n",
    "    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "✅ 已生成 YAML 文件: output/分组yaml1/项目基本信息_K39+726_圆管涵.yaml\n",
      "✅ 已生成 YAML 文件: output/分组yaml1/项目基本信息_K40+426_圆管涵.yaml\n",
      "✅ 已生成 YAML 文件: output/分组yaml1/项目基本信息_K42+867_圆管涵.yaml\n"
     ]
    }
   ],
   "source": [
    "all_processed_data = updater.run(filtered_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "#打开 yaml\n",
    "import yaml\n",
    "all_processed_data = yaml.safe_load(open(\"/Users/chenhongbin/myapp1/highway-information/output/分组yaml1/项目基本信息_K39+726_圆管涵.yaml\", \"r\", encoding=\"utf-8\"))\n",
    "\n",
    "\n",
    "# processor = RuleProcessor()\n",
    "# processor.run_pipeline_for_projects(all_processed_data.values(), base_output_folder=\"outputs\", max_workers=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'project_list': [{'instance_mapping': {'GL105': [{'总体': {'具体部位': '八字墙',\n",
       "       '工程地点及桩号': 'K39+726圆管涵',\n",
       "       '检查内容（或主要工序）': '施工放样、高程、模板、涵管安装、砼浇筑等'}}],\n",
       "    'JS101': [{'总体': {'设计坐标(X,Y)': [3243273.926, 509154.842]}}],\n",
       "    'JS103': [{'八字墙基础底': {'施工部位': 'K39+726圆管涵  八字墙基础底', '设计高程': 27.15}},\n",
       "     {'八字墙基础顶': {'施工部位': 'K39+726圆管涵  八字墙基础顶', '设计高程': 27.18}},\n",
       "     {'八字墙墙顶': {'施工部位': 'K39+726圆管涵  八字墙墙顶', '设计高程': 27.224999999999998}}],\n",
       "    'JS107': [{'八字墙': {'JS107规则类型': 1,\n",
       "       'instance_id': '八字墙',\n",
       "       '基础厚度': 538,\n",
       "       '基础宽度': 2050,\n",
       "       '基础顶高程': 59.46}},\n",
       "     {'八字墙基础': {'基础顶高程': 27.18}}],\n",
       "    'JS111': [{'八字墙基础': {'断面尺寸宽度(直径)设计值': 161.4,\n",
       "       '断面尺寸长度设计值': 40.83,\n",
       "       '断面尺寸高（厚）度设计值': 60,\n",
       "       '施工部位': 'K39+726圆管涵  八字墙基础'}},\n",
       "     {'八字墙墙身': {'断面尺寸宽度(直径)设计值': 53.8,\n",
       "       '断面尺寸长度设计值': 40.83,\n",
       "       '断面尺寸高（厚）度设计值': 205,\n",
       "       '施工部位': 'K39+726圆管涵  八字墙墙身'}}],\n",
       "    'JS601_1': [{'八字墙基础': {'实际混凝土（砂浆）用量': 16,\n",
       "       '施工部位': 'K39+726圆管涵  八字墙基础',\n",
       "       '混凝土强度（砂浆）等级': 'C25',\n",
       "       '设计混凝土（砂浆）用量': 15}},\n",
       "     {'八字墙墙身': {'实际混凝土（砂浆）用量': 17,\n",
       "       '施工部位': 'K39+726圆管涵  八字墙墙身',\n",
       "       '混凝土强度（砂浆）等级': 'C25',\n",
       "       '设计混凝土（砂浆）用量': 18}}]},\n",
       "   '宽': 2759,\n",
       "   '施工单位': '浙江交工宏途交通建设有限公司',\n",
       "   '施工日期': '2024/05/31',\n",
       "   '施工部位': 'K39+726圆管涵',\n",
       "   '监理单位': '浙江浙中建设工程管理有限公司',\n",
       "   '设计坐标(X,Y)': [3242620.909, 500173.892],\n",
       "   '长': 44.5}]}"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "all_processed_data"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
